package com.bjxst;
/**文件字节流可以处理所有的文件*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileCopyTools {
    public static void main(String[] args) {
        copyFile("e:/picture/1002.jpg","e:/cc.jpg");
    }
    /**文件拷贝方法*/
    //传入文件路径与文件名  传出文件路径与文件名
    //用静态方法，调用时不用实例化
    public static void copyFile(String src,String des){
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try{
            bis = new BufferedInputStream(new FileInputStream(src));
            bos = new BufferedOutputStream(new FileOutputStream(des));
            int temp = 0;
            while ((temp = bis.read()) != -1){
                bos.write(temp);
            }
            bos.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(bis != null)bis.close();
                if(fis != null)fis.close();
                if(bos != null)bis.close();
                if(fos != null)fos.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

}
